<?php
namespace app\home\controller;

use app\common\model\cms\ClassModel;
use think\facade\Env;
use think\facade\View;
use traits\controller\JumpTraits;
use traits\controller\ListTraits;
use traits\controller\ViewTraits;

/**
 * 控制器基础类
 */
abstract class BaseController
{

  use JumpTraits;
  use ListTraits;
  use ViewTraits;

  /**
   * Request实例
   * @var \think\Request
   */
  protected $request;

  /**
   * 应用实例
   * @var \think\App
   */
  protected $app;

  /**
   * 控制器中间件
   * @var array
   */
  protected $middleware = [];
  protected $cmsClass;
  protected $treeClass;

  /**
   * 构造方法
   * @access public
   */
  public function __construct()
  {
    $this->app       = app();
    $this->request   = $this->app->request;
    $classModel = new ClassModel();
    $this->cmsClass = $classModel->getList();
    $this->treeClass = $classModel->getTree();
    $this->assign('tree_class',$this->treeClass);
    $this->assign('cms_class',$this->cmsClass);
    $viewPath = root_path()."view".DIRECTORY_SEPARATOR."home".DIRECTORY_SEPARATOR."pc".DIRECTORY_SEPARATOR;
    $viewMobilePath = root_path()."view".DIRECTORY_SEPARATOR."home".DIRECTORY_SEPARATOR."mobile".DIRECTORY_SEPARATOR;
    View::config(['view_depr'=>'/']); //设置模板分隔符
    //PC端主题设置
    View::config(['view_path'=>$viewPath]);
    //手机端主题设置
    if ($this->request->isMobile()) {
      View::config(['view_path'=>$viewMobilePath]);
     /* if (!View::exists('')) { //不存在手机模板使用PC模板
          View::config(['view_path'=>$viewPath]);
      }*/
    }
  }

}
